
/**
 *  nginx 上线
 * @param ip nginx服务器ip
 * @param host   上线的ip:port
 * @param fileName  nginx配置文件名
 */
void add(List<String> ips,  String host , String fileName) {
    for (String ip in ips) {
        ssh.loginSshVoid(ip, "sh /home/deployer/nginx-scripts/modify_upstream_server.sh  add ${fileName} ${host} ")
    }
    println("✅${fileName}  上线${host}")
}


/**
 *  nginx 下线
 * @param ip nginx服务器ip
 * @param host   下线的ip:port
 * @param fileName  nginx配置文件名
 */
void del(List<String> ips,  String host , String fileName) {
    print(ips)
    withCredentials([sshUserPrivateKey(
            credentialsId: 'ssh_key',  // 凭证 ID
            keyFileVariable: 'SSH_KEY',
            usernameVariable: 'USER'
    )]) {
        for (String ip in ips) {
            ssh.sshVoid(ip, "sh /home/deployer/nginx-scripts/modify_upstream_server.sh  del ${fileName} ${host} ")
        }

    }
    println("✅${fileName}  下线${host}")
//   下线后 睡眠60秒等待程序执行完
    sleep(60)
}

def getNginxIp(String ip , String fileName) {
    ssh.call(ip)
    return ssh.loginSshReturn(ip, "sh /home/deployer/nginx-scripts/get_upstream_servers.sh  ${fileName} ")
}